package com.chat.chatting.controller;

import com.chat.chatting.dto.UserInfoDto;
import com.chat.chatting.entity.ApplicationEntity;
import com.chat.chatting.service.ApplicationService;
import com.chat.chatting.service.FriendService;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Application)表控制层
 *
 */
@RestController
@RequestMapping("application")
public class ApplicationController {

    @Resource
    private ApplicationService applicationService;
    @Resource
    private FriendService friendService;

    /**
     * 通过用户ID查询自己被申请的未处理数据
     * 默认返回前十条
     * @param pageNum 页数
     * @param pageSize 页码大小
     * @param userID 用户ID
     * @return
     */
    @GetMapping("getUnsettledList")
    public List<ApplicationEntity> getUnsettledList(@Param("pageNum") Integer pageNum,
                                           @Param("pageSize") Integer pageSize,
                                           @Param("userID") Integer userID) {
        return applicationService.getUnsettledList(pageNum, pageSize, userID);
    }
//    /**
//     * 通过用户ID查询自己被申请数据
//     * 默认返回前十条
//     * @param pageNum 页数
//     * @param pageSize 页码大小
//     * @param userID 用户ID
//     * @return
//     */
//    @GetMapping("getPage")
//    public List<ApplicationEntity> getPage(@Param("pageNum") Integer pageNum,
//                                           @Param("pageSize") Integer pageSize,
//                                           @Param("userID") Integer userID) {
//        return applicationService.getPage(pageNum, pageSize, userID);
//    }

    /**
     * 提出申请
     *
     * @param applicantID 申请者ID
     * @param byApplicantID 被申请者ID
     * @param applicationRemark 申请理由/备注信息
     * @return 申请成功返回true
     */
    @GetMapping("apply")
    public boolean apply(@Param("applicantID") Integer applicantID,
                         @Param("byApplicantID") Integer byApplicantID,
                         @Param("applicationRemark") String applicationRemark) {
        return applicationService.apply(applicantID, byApplicantID, applicationRemark);
    }

    /**
     * 同意申请
     *
     * @param applicantID 申请者ID
     * @param byApplicantID 被申请者ID
     * @return 同意申请成功返回true
     */
    @GetMapping("agree")
    public boolean agree(@Param("applicantID") Integer applicantID,
                         @Param("byApplicantID") Integer byApplicantID) {
        return applicationService.agree(applicantID, byApplicantID);
    }

    /**
     * 拒绝申请
     *
     * @param applicantID 申请者ID
     * @param byApplicantID 被申请人ID
     * @return 拒绝申请成功返回true
     */
    @GetMapping("reject")
    public boolean reject(@Param("applicantID") Integer applicantID,
                          @Param("byApplicantID") Integer byApplicantID) {
        return applicationService.reject(applicantID, byApplicantID);
    }

    /**
     * 查看他人信息
     *
     * @param selfID   本人ID
     * @param friendID 对方ID
     * @return
     */
    @GetMapping("getUserInfo")
    public UserInfoDto getUserInfo(@Param("selfID") Integer selfID, @Param("friendID") Integer friendID) {
        return friendService.getUserInfo(selfID, friendID);
    }


}